<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>微博首页</h1>
<div>
    <div v-if="user.nickname!=null">
        <h2>欢迎{{user.nickname}}回来!</h2>
        <a href="/send.html">发布微博</a>
        <a href="javascript:void (0)" @click="logout()">退出登录</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册微博</a>
        <a href="/login.html">登录微博</a>
    </div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            user:{
            }
        },
        methods:{
            logout(){
                axios.get("/logout",v.user).then(function (response) {
                    if (confirm("您确定退出吗?")){
                        v.user={}
                    }
                })
            }
        },
        created:function () {
            axios.get("/session").then(function (response) {
                v.user = response.data;
            })
        }
    })
</script>
</body>
</html>